#include "MenuSystem.h"
#include "IrControl.h"
#include "Menu/Tool/frame.h"

#define ITEM_VOL_DOWN		(0)
#define ITEM_VOL_UP		(1)
#define MENU_VOL_BUTTON_QTY   (2)
#define ITEM_VOL_UPDATE (2)

TRect		VolumeTouchRect[MENU_VOL_BUTTON_QTY];
TPosCoor	VolumeItemPos[MENU_VOL_BUTTON_QTY] = { {36,222}, {588,222} };
TPosCoor	VolumeDispPos = {330,191};
TPosCoor	BarCoverDispPos = {209,236};
TPosCoor	BarDispPos = {215,237};
TRect	VolInfoPos= {330,191,400,226};
int		VolumeFocus = -1;
TFrame		VolumeFrame;
char		VolumeInfoStr[3];
unsigned char		VOLvalue = 5;
unsigned char vol_data [5] = {0xe0,0x03,0x05,0x03,0xEB};
extern	unsigned char read_info_data[10];
static 	int count = 0;
static int temp = 0;
extern int lastID;
extern unsigned char rece_handle;
extern unsigned char dtpresent_flag;	
extern pthread_cond_t dt_cond;


struct _VolumePos VolumePos = 
 {	
 	{0,8},
 	{45,15},
	{111,25},
	{111,25},	
	{620,25},
	34,
	8,						
 };

int  VolInfoUpdata(void)
{
	
	if (read_info_data[3] == ID_SCREEN_INFO_VOLUME)
		VOLvalue = read_info_data[4];		
			return 0;
}

void VolumeDrawInfo( TCanvas *pCanvas)
{

	
}


void VolumeDrawBackgroup(TCanvas *pCanvas)
{
	
}

void VolumeDrawItem( TCanvas *pCanvas, int idx, BOOL bfocus )
{
	
	
}

void VolumeDraw( BOOL bDrawAll )
{

}

int VolumeGetTouchID( TPosCoor pos)
{
	
}

BOOL VolumeBtnEnter(int idx)
{

}


void VolumeInit()
{
/*	if (ir_GetCurrentID() != IR_VOLUME_INIT)
		{
			lastID = ir_GetCurrentID();			
		}
	ir_SetCurrentID( IR_VOLUME_INIT );

	frm_Create( &VolumeFrame, FRM_NO_TITLE|FRM_NO_TASK, "" );
	VolumeDraw( TRUE );
	count = 0;
	temp = 0;
	*/
}
/*****************************
function:message_dispatch

 return:
  0: successful
  1: need other menu handle
  -1:failure
*****************************/
static int message_dispatch (void)
{
	int rc = 1;	
	
	//printf ("volume__%x %x %x %x %x %x___\n",read_info_data[0],\
	read_info_data[1],read_info_data[2],read_info_data[3],read_info_data[4],read_info_data[5]);
	switch (read_info_data[2])
	{
					case	ID_POWER:						
						break;
						
					case	ID_DISPLAY_SCREEN:	
							switch (read_info_data[3])
								{
									case 	ID_SCREEN_MENU:
											MenuMainInit();
										break;		
									case 	ID_SCREEN_RADIO:
											MenuRadioInit();
										break;									
									case	ID_SCREEN_CDLOAD:											
									case	ID_SCREEN_CDDISP:
									case	ID_SCREEN_MP3DISP:
									case	ID_SCREEN_NODISC:
									case	ID_SCREEN_DISCERR:
									case	ID_SCREEN_EJECT:
											MenuCdInit();
											rece_handle = 0;
										break;
									case	ID_SCREEN_MEDIEA:
											MenuMediaInit();
										break;
									
									case 	ID_SCREEN_NAVI:
										MenuNaviInit();
										break;	
										
									case	 	ID_SCREEN_AUDIODISP:
											MenuAudioInit();
											break;	
									case		ID_SCREEN_VIDEODISP:
										VolumeInit();
										break;	
									case		ID_SCREEN_EQDISP:
											AudioEQInit();
										break;	
									case	 	ID_SCREEN_BASTRA:
											AudioBASInit();
										break;	
									case		ID_SCREEN_FADBAL:	
											AudioFADInit();							
										break;	
									}
									rc = 0;//if handled, clear this flag.	
							read_info_data[0] = 0;											
						break;
						
					case	ID_KEY_STATUS:						
						break;
						
					case	ID_SCREEN_INFO:						
								if (read_info_data[3] == 0x10 )
								{
									VolumeDrawInfo( VolumeFrame.pCanvas);									
									dtpresent_flag++;		
									pthread_cond_signal(&dt_cond);
									//dt_Present();									
									count = 0;	
									temp = 0;
													
								}
								break;
						
					case	ID_KEYPAD:	
						switch (read_info_data[3])
							{
									case 	ID_MUTE:										
									case	ID_DMUTE:	
										break;									
									case 	ID_SEEKUP:
									case 	ID_SEEKDN:
										break;
										
									case 	ID_DEST:
									case 	ID_NAVI:
										MenuNaviInit();
										break;
										
									case 	ID_FMAM:
										MenuRadioInit();
										break;
									case 	ID_CD:
										MenuCdInit();
										break;				
									case 	ID_MEDIA:
										MenuMediaInit();								
										break;
									case 	ID_MENU:
										MenuMainInit();
										break;
										
									case	ID_TVAUX:
										
										break;
							}	
							rc = 0;//if handled, clear this flag.	
							read_info_data[0] = 0;
						break;
					case 	ID_BAND_SEL:
							MenuRadioInit();
							rc = 0;//if handled, clear this flag.	
							read_info_data[0] = 0;
						break;	
						
					default:	
							rc = -1;						
						}						
}



void VolumeInput(UInt32 key)
{
/*		int flag;


		if ( key == IRC_READ_INFO)
		{
			flag =message_dispatch ();
			if (flag == -1)
				printf ("main menu handle receive data error!\n");
			if (flag == 0)
				{
					//printf ("main menu handle receive data success!\n");
					return;
				}			
		}
		
	if( key == IRC_TOUCH_DOWN || key == IRC_TOUCH_UP )
	{
		int focus;
		TPosCoor pos;
		dt_ClipTouchGetXY( &pos.x, &pos.y );
		if( key == IRC_TOUCH_DOWN )
		{
			if( LastKey ==IRC_TOUCH_UP )
			{
				if( ( VolumeFocus = VolumeGetTouchID( pos )) != -1 )
				{
					VolumeDrawItem( VolumeFrame.pCanvas, VolumeFocus, TRUE );
					dtpresent_flag++;		
					pthread_cond_signal(&dt_cond);
					//dt_Present();
					
				}
			}
		}
		else
		{
			if( ( focus = VolumeGetTouchID( pos ) ) == VolumeFocus )
				VolumeBtnEnter( VolumeFocus );
			else if( VolumeFocus != -1 )
			{
				VolumeDrawItem( VolumeFrame.pCanvas, VolumeFocus, FALSE );
				dtpresent_flag++;		
				pthread_cond_signal(&dt_cond);
				//dt_Present();
			}
			VolumeFocus = -1;
		}		
		LastKey = key;//hangsheng add 071126
	}
	
		count ++;
		if (count >0xFF00)
			{
				temp ++;
				count = 0;
			}
		if (temp > 10)
			{
				//ir_SetCurrentID( lastID);
				BackToLastID(lastID);	
				count = 0;	
				temp = 0;			
			}
			*/
}
